include Makefile.d

all: prepare build 

clean:
	@rm -rf $(OUTDIR) -v
	
prepare:
	@if [ ! -d $(OUTDIR) ]; then \
	    mkdir -p $(OUTDIR)/bin; \
	    mkdir -p $(OUTDIR)/conf; \
	    mkdir -p $(OUTDIR)/log; \
	    mkdir -p $(OUTDIR)/lib; \
	    mkdir -p $(OUTDIR)/status; \
	fi

build:
	$(CC) ./src/*.cpp $(CPPFLAGS) $(LDFLAGS) $(INCLUDES) -o $(OUTDIR)/bin/$(TARGETS)
	@cp conf/$(TARGETS).conf $(OUTDIR)/conf
	@cp shell/control.conf $(OUTDIR)/conf
	@cp shell/control.inc $(OUTDIR)/bin
	@cp shell/control.func $(OUTDIR)/bin
	@cp shell/control $(OUTDIR)/bin
	@chmod u+x $(OUTDIR)/bin/control
	@chmod u+x $(OUTDIR)/bin/$(TARGETS)

static_lib: prepare
	$(CC) -c ./src/*.cpp $(CPPFLAGS) $(INCLUDES) $(LDFLAGS)
	@mv *.o ./output/lib
	ar -rs ./output/lib/lib$(TARGETS).a ./output/lib/*.o
	rm ./output/lib/*.o